package 排序;

//冒泡排序
public class bubutext {
    public static void main(String[] args) {
        int[] arr = {4, 2, 1, 5, 3};
        int[] paixu_text = paixu(arr);
        int[] paixu1_text = paixu1(arr);
        print_this(paixu_text);
        print_this(paixu1_text);
    }
    //  1
    private static int[] paixu1(int[] arr) {
        int i = 0;
        while (i < arr.length - 1) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                }
            }
            i += 1;
        }
        return arr;
    }
//打印数据
    private static void print_this(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.print("\n");
    }
//   2
    private static int[] paixu(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                }
            }
        }
        return arr;
    }
}
